const jwt = require('jsonwebtoken')
const { PRIVATE_KEY, PUBLIC_KEY } = require('../app/config')

// 生成token
const createToken = (option) => {
  const token = jwt.sign(option, PRIVATE_KEY, {
    expiresIn: 60 * 60 * 24 * 15,
    algorithm: 'RS256'
  })
  return token
}

// 验证token
const checkToken = (token) => {
  const result = jwt.verify(token, PUBLIC_KEY, {
    algorithms: ["RS256"]
  })
  return result
}

module.exports = {
  createToken,
  checkToken
}
